//package com.ocl.www.document;
//
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.List;
//
//import org.apache.solr.client.solrj.SolrQuery;
//import org.apache.solr.client.solrj.SolrServerException;
//import org.apache.solr.client.solrj.impl.HttpSolrClient;
//import org.apache.solr.client.solrj.response.QueryResponse;
//import org.apache.solr.common.SolrDocumentList;
//import org.apache.solr.common.SolrInputDocument;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.solr.core.mapping.SolrDocument;
//
//import com.ocl.www.domain.Article;
//import com.ocl.www.service.ArticleService;
//
//@SolrDocument
//public class ArticleDoc{
//
//	@Autowired
//	private HttpSolrClient solrClient;
//	@Autowired
//	private ArticleService articleService;
//
//	public  void createArticleIndex() {
//		// TODO Auto-generated method stub
//		System.out.println("启动服务会不会执行此函数？不会");
//        List<Article> listart = null;
//        try {
//            listart = articleService.selectAllArticle();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        int i = 0;
//        List<SolrInputDocument> docList = new ArrayList<SolrInputDocument>();
//        for(Article obj : listart){
//            SolrInputDocument doc = new SolrInputDocument();
//            doc.addField("id",i++);
//            doc.addField("arid_num",obj.getArticleId());
//            doc.addField("arauthor_str",obj.getAuthor());
//            doc.addField("artitle_str", obj.getTitle());
//            docList.add(doc);
//        }
//        try {
//        	solrClient.add(docList);
//        	solrClient.commit();
//        } catch (SolrServerException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        this. queryDocs();
//	}
//
////	@Override
////	public SolrDocumentList queryArticles() {
////		// TODO Auto-generated method stub
////		return null;
////	}
////	  private String solrUrl;
////    private SolrClient client;
////    private int num = 10;
////    private String zkUrl;
////    private String collectionName;
////
////    private SolrClient createNewSolrClient() {
////        try {
////            System.out.println("server address:" + solrUrl);
////            HttpSolrClient client = new HttpSolrClient(solrUrl);
////            client.setConnectionTimeout(30000);
////            client.setDefaultMaxConnectionsPerHost(100);
////            client.setMaxTotalConnections(100);
////            client.setSoTimeout(30000);
////            return client;
////        } catch (Exception ex) {
////            throw new RuntimeException(ex);
////        }
////    }
////
////    private SolrClient createCouldSolrClient() {
////        CloudSolrClient client = new CloudSolrClient(zkUrl);
////        client.setZkClientTimeout(30000);
////        client.setZkConnectTimeout(50000);
////        client.setDefaultCollection(collectionName);
////        return client;
////    }
////
////    public void close() {
////        try {
////            client.close();
////        } catch (IOException e) {
////
////            e.printStackTrace();
////        }
////    }
////
////    public ArticleDoc(String solrUrl, int num) {
////        this.solrUrl = solrUrl;
////        this.client = createNewSolrClient();
////        this.num = num;
////    }
////
////    public ArticleDoc(String zkUrl, int num, String collection) {
////        this.zkUrl = zkUrl;
////        this.num = num;
////        collectionName = collection;
////        this.client = createCouldSolrClient();
////    }
////
////    public void createDocs() {
////        System.out.println("======================add doc ===================");
////        Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
////        for (int i = 1; i <= num; i++) {
////            SolrInputDocument doc1 = new SolrInputDocument();
////            doc1.addField("id", UUID.randomUUID().toString(), 1.0f);
////            doc1.addField("name", "bean");
////            doc1.addField("equIP_s", "192.168.2.104");
////            doc1.addField("level_s", "4");
////            doc1.addField("collectPro_s", "ffffffffffffffffffffjajajajajajdddddddddd");
////            doc1.addField("sourceType_s", "miaohqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
////            doc1.addField("filePath_s", "/home/xxxx/test");
////            doc1.addField("filename_s", "zhonggggmaiaiadadadddddddddddddddddddddddddd");//            doc1.addField("_route_", "shard1");
////            docs.add(doc1);
////        }
////        try {
////            UpdateResponse rsp = client.add(docs);
////            System.out.println("Add doc size" + docs.size() + " result:" + rsp.getStatus() + " Qtime:" + rsp.getQTime());
////
////            UpdateResponse rspcommit = client.commit();
////            System.out.println("commit doc to index" + " result:" + rsp.getStatus() + " Qtime:" + rsp.getQTime());
////
////        } catch (SolrServerException | IOException e) {
////            // TODO Auto-generated catch block
////            e.printStackTrace();
////        }
////
////    }
////
//    public void queryDocs() {
//        SolrQuery query = new SolrQuery();
//        query.setQuery("artitle_str:啊");
//        QueryResponse response = null;
//        try {
//            response = solrClient.query(query);
//            System.out.println(response.toString());
//            System.out.println();
//            SolrDocumentList docs = response.getResults();
//            System.out.println("文档个数：" + docs.getNumFound());
//            System.out.println("查询时间：" + response.getQTime());
//            for (org.apache.solr.common.SolrDocument doc : docs) {
//                System.out.println("artitle_str: " + doc.getFieldValue("artitle_str"));
//            }
//        } catch (SolrServerException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//    }
////
////    public void deleteById(String id) {
////        System.out.println("======================deleteById ===================");
////        try {
////            UpdateResponse rsp = client.deleteById(id);
////            client.commit();
////            System.out.println("delete id:" + id + " result:" + rsp.getStatus() + " Qtime:" + rsp.getQTime());
////        } catch (SolrServerException | IOException e) {
////            e.printStackTrace();
////        }
////    }
////
////    public void deleteByQuery(String queryCon) {
////        System.out.println("======================deleteByQuery ===================");
////        UpdateResponse rsp;
////
////        try {
////            UpdateRequest commit = new UpdateRequest();
////            commit.deleteByQuery(queryCon);
////            commit.setCommitWithin(5000);
////            commit.process(client);
////            System.out.println("url:"+commit.getPath()+"\t xml:"+commit.getXML()+" method:"+commit.getMethod());
//////            rsp = client.deleteByQuery(queryCon);
//////            client.commit();
//////            System.out.println("delete query:" + queryCon + " result:" + rsp.getStatus() + " Qtime:" + rsp.getQTime());
////        } catch (SolrServerException | IOException e) {
////            // TODO Auto-generated catch block
////            e.printStackTrace();
////        }
////
////    }
////
////    public void updateField(String id,String fieldName, Object fieldValue) {
////        System.out.println("======================updateField ===================");
////        HashMap<String, Object> oper = new HashMap<String, Object>();
//////        多值更新方法
//////        List<String> mulitValues = new ArrayList<String>();
//////        mulitValues.add(fieldName);
//////        mulitValues.add((String)fieldValue);
////        oper.put("set", fieldValue);
////
////        SolrInputDocument doc = new SolrInputDocument();
////        doc.addField("id", id);
////        doc.addField(fieldName, oper);
////        try {
////            UpdateResponse rsp = client.add(doc);
////            System.out.println("update doc id" + id + " result:" + rsp.getStatus() + " Qtime:" + rsp.getQTime());
////            UpdateResponse rspCommit = client.commit();
////            System.out.println("commit doc to index" + " result:" + rspCommit.getStatus() + " Qtime:" + rspCommit.getQTime());
////
////        } catch (SolrServerException | IOException e) {
////            e.printStackTrace();
////        }
////
////    }
////
////    public void createArticleDoc(){
////
////      String zkUrl = "192.168.1.73:8002";
////      ArticleDoc sc = new ArticleDoc(zkUrl, 2, "core1");
////      // 添加文档
////      sc.createDocs();
////      sc.close();
////
////    }
////
////
////
////    public void queryArticleDoc(){
////
////    	String url = "http://192.168.1.73:8002/solr/core1";
////        ArticleDoc ss = new ArticleDoc(url, 2);
////        // 查询文档
////        ss.queryDocs();
////        ss.close();
////
////    }
//
//
//
//
//
//
////    public static void main(String args[]) {
////        String url = "http://127.0.0.1:8983/solr/test201606";
////        String zkUrl = "127.0.0.1:9983";
//////        PropertyConfigurator.configure("./etc/log4j.properties");
////        ArticleDoc ss = new ArticleDoc(url, 2);
////        ArticleDoc sc = new ArticleDoc(zkUrl, 2, "test201607");
////        // 添加文档
////        sc.createDocs();
////
////        // 删除文档
//////        sc.deleteById("00cda454-bd3d-4945-814f-afa7110dcd21");
////         sc.deleteByQuery("name:bean");
////
////        //更新文档
////        sc.updateField("bd67564f-4939-4de1-9a83-3483ebbbbbee", "name", "1233313131313");
////
////        sc.close();
////
////
////        // 查询文档
////        ss.queryDocs();
////        ss.close();
////
////    }
//
//}
